#include "bitwise.h"

namespace BitOp {
	 unsigned char SpliceByte(const unsigned char Byte, int offset, int count) {
		// Temp byte to operate on. Initialized to 0 to enable the Bitwise
		// operators their valid operation. Will contain "On/Off"
		// information on which bits do we want to take.
		unsigned char TempByte=0;
		// Flag 1 the bits we are interested in getting. 
		for (int i=0; i<count; ++i) {
			TempByte = TempByte | static_cast<unsigned char>(pow(2,offset+i));
		}
		// Copy only the bits we are interested in. This is done using a
		// simple Bitwise AND operation between the flags byte and our
		// original byte.
		unsigned char ReturnByte=Byte&TempByte;
		// The fix the new byte's offset, so it doesn't begin with
		// excessive 0s.
		ReturnByte=ReturnByte>>(offset);
		// Return the byte.
		return ReturnByte;
	}
}

